package com.apestech.formwork.run.core;

import com.apestech.formwork.xml.core.exec.SingleNode;
import com.apestech.framework.db.SqlSession;
import com.apestech.framework.json.JSONArray;
import com.apestech.framework.json.JSONObject;

/**
 * define结点执行
 *
 * @author hup
 * @create 2018-04-28-10:34
 */
public class ExecDefine {

    private SingleNode node;
    private JSONObject data;
    private JSONObject input;
    private JSONObject output;
    private boolean success=true;
    private SqlSession session;
    private String error;
    private String errorId;

    public ExecDefine(SingleNode node){
        this.node=node;
    }

    public void setData(JSONObject data){
        this.data=data;
    }

    public void setSqlSession(SqlSession session){
        this.session=session;
    }

    public void expain() throws Exception {
        this.input=ExecUtil.getInput(node, data, this.session);
        Object obj= ExecUtil.execProcess(node.getParam(), this.input, this, this.session);
        JSONArray list= null;
        if(obj!=null){
            list= (JSONArray) obj;
            this.output= (JSONObject) list.get(0);
            this.success=true;
        } else {
            this.success=false;
            this.errorId="NOT_DEFINE_FIND";
            this.error="没有符合条件的数据！";
        }
    }

    public JSONObject getOutput() {
        return output;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getError() {
        return error;
    }

    public String getErrorId() {
        return errorId;
    }
}
